var express = require('express');
var getRouter = express.Router();
var postRouter = express.Router();
var axios = require('axios');
var userDao = require('../DAO/userDAO');
// var fs = require('fs');

var rootApi = "http://112.74.105.17:20003/question-bank"
/* GET users listing. */
getRouter.get('/userLogin', function (req, res, next) {
    // console.log(req.query.data)
    // var thisApi = '/wx/answer/stem'
    // axios.get(rootApi + thisApi + questionId)
    //     .then(function (response) {
    //         res.send(response.data);
    //     })
    //     .catch(function (error) {
    //         console.log(error);
    //     });

});

postRouter.post('/userLogin', function (req, res, next) {
    //租户id 757021031830388736 是我们组的，必选参数，其他可以不要，所以租户id在这里写死了
    // var thisApi = '/wx/answer/stem'
    //查询用户信息-手机号-密码
    var userName
    var pword
    var userId
    // var check_item
    console.log("At least iam coming!")

    userId=JSON.stringify(req.body.userId)
    userId=userId.substring(1, (userId.length - 1))

    var check_flight_sql = "SELECT userName,pword FROM userInfo WHERE userId="+userId
    console.log(check_flight_sql);
    userDao.queryAll(check_flight_sql, res, function (check_result) {
        var check_item = JSON.stringify(check_result);
        console.log(check_item)
        res.send(check_item)
    });

    // res.send(userName+":"+pword)
    //写到这里，随机返回一道题接口
    // axios.post(rootApi + thisApi, {
    //     gradeName: gradeName,
    //     groupName: groupName,
    //     subject: subject,
    //     tenantId: tenantId
    // })
    //     .then(function (response) {
    //         res.send(response.data)
    //     })
    //     .catch(function (error) {
    //         console.log(error);
    //     });
});

exports.get = getRouter;
exports.post = postRouter;
// module.exports = router;
